import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { AtAvatar } from 'taro-ui'
import './myDoctor.scss'
import touxiang from '../../img/touxiang3.png'
import app from '../../main'

export default class MyDoctor extends Component {

    config = {
        navigationBarTitleText: '我的医生'
    }
    constructor() {
        super(...arguments)
        this.state = {
            //医生数据
            dcoArray: [
            ]
        }
    }

    handleClick(){
        app.navigateTo('../findDoctor/findDoctor')
    }
    
    //跳转到医生首页
    navTo(id){
        console.log(id)
        app.navigateTo('../doctorindex/doctorindex?id='+id)
    }


    offset = 0;
    length = 20;
    total = 0;
    isFinlsh = false;

    //调用接口获取数据
    getDate(){
    // //将接口返回数据与原来数据拼接
    let me = this;
    // let data = {token:'1',offset:this.offset,length:this.length}
    let data = {offset:this.offset,length:this.length}
    let dataArray=[]
    app.post('web/myself/myDoctorList',data,function(res){
        console.log('e',res)
        dataArray = me.state.dcoArray.concat(res.data.result.list)
        me.total = res.data.result.total
        me.setState({
            dcoArray:dataArray
        })
        })
    }

    //上拉加载
    onReachBottom() {
        if ((this.offset + this.length) < this.total) {
            app.toast('正在加载----')
            this.offset = this.offset + this.length;
            this.isFinlsh = false;
            this.getDate();
        } else {
            app.toast('没有更多数据了咯')
            this.isFinlsh = true;
        }
    }

    componentWillMount() { }

    componentDidMount() {
        this.getDate();
    }

    componentWillUnmount() { }

    componentDidShow() { }

    componentDidHide() { }

    render() {
        let zl = this.state.dcoArray.map((item) => {
            return <View className='ZhangLiMing' onClick={this.navTo.bind(this,item.id)}>
                <View>
                    <AtAvatar
                        className='TouXinagSize'
                        image={item.head_image}
                        circle
                    />
                </View>
                <View className='infoContent'>
                    <View className='contentTitle'>
                        <Text className='name'>{item.name}</Text>
                        <Text>{item.positional_title}</Text>
                    </View>
                    <View className='content2'>
                        <Text>{item.hospital}</Text>
                    </View>
                    <View className='content3'>
                        <Text>擅长: {item.speciality}</Text>
                    </View>
                </View>
            </View>
        })
        return (
            <View>
                {zl}
                <View className='noLoad' onClick={this.handleClick}>
                    找更多眼科专家
            </View>
            </View>
        )
    }
}
